import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vuex from 'vuex'
import store from './store'
import PubSub from 'pubsub-js'
import VueLazyLoad from 'vue-lazyload'

// 导入全局初始化样式
import './assets/index.css'
import moment from 'moment'
moment.locale('zh-cn')

Vue.filter('MomentFromNow', function (time) {
  return time = moment(time).fromNow()
})
Vue.filter('playTimeFormat', function (originVal) {
  let duration = originVal
  let min = parseInt(duration / 1000 / 60)
  if (min < 10) {
    min = '0' + min
  }
  let sec = parseInt((duration / 1000) % 60)
  if (sec < 10) {
    sec = '0' + sec
  }
  return `${min}:${sec}`
})

Vue.filter('playNumFormat', function (playCount) {
  if (playCount > 100000) {
    return parseInt(playCount / 10000) + '万'
  }
  return playCount
})

Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

Vue.prototype.$pubSub = PubSub
import APlayer from '@moefe/vue-aplayer';

Vue.use(APlayer, {
  defaultCover: 'https://github.com/u3u.png',
  productionTip: true,
});
Vue.config.productionTip = false


Vue.use(VueLazyLoad, {
  loading: 'Music/imgs/loading-svg/music_bubble.svg'
});

Vue.use(Vuex)
new Vue({
  store,
  render: h => h(App),
  // 挂载到Vue示例上
  router
}).$mount('#app')
